package com.umgsai.aop.level3;

import java.util.Arrays;

/**
 * Created by shangyidong on 17/6/29.
 */
public class ArithmeticCaculatorProxy implements ArithmeticCalculator {
    //要代理的对象
    private ArithmeticCalculator arithmeticCalculator;

    public ArithmeticCaculatorProxy(ArithmeticCalculator arithmeticCalculator){
        this.arithmeticCalculator = arithmeticCalculator;
    }

    private void before(int ... args) {
        System.out.println("The method add begins with " + Arrays.toString(args));
    }

    private void after(int ... args) {
        System.out.println("The method add ends with " + Arrays.toString(args));
    }

    public int add(int i, int j) {
        before(i, j);
        int result = arithmeticCalculator.add(i, j);
        after(result);
        return result;
    }

    public int sub(int i, int j) {
        before(i, j);
        int result = arithmeticCalculator.sub(i, j);
        after(result);
        return result;
    }

    public int mul(int i, int j) {
        before(i, j);
        int result = arithmeticCalculator.mul(i, j);
        after(result);
        return result;
    }

    public int div(int i, int j) {
        before(i, j);
        int result = arithmeticCalculator.div(i, j);
        after(result);
        return result;
    }
}
